package io.github.fb513.api.model;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class PageInfo {
    private int pageNum;
    private int pageSize;
    private long totalPage;
    private long totalRecord;

    public PageInfo() {}

    public PageInfo(int pageNum, int pageSize) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
    }

    public void setTotalRecord(long totalRecord) {
        this.totalRecord = totalRecord;
        this.totalPage = (totalRecord - 1) / getPageSize() + 1;
    }

    public int getPageNum() {
        return Math.max(pageNum, 1);
    }

    public int getPageSize() {
        if (pageSize < 1) {
            return 12;
        }
        return pageSize;
    }

    public boolean noData(int pageNum) {
        return totalRecord <= 0 || totalPage < pageNum;
    }
}
